package com.example.dialoglibrary;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.TimePicker;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.example.dialoglibrary.adapter.DialogAdapter;
import com.example.dialoglibrary.dialog.CustomDialog;
import com.example.dialoglibrary.dialog.ShowImagesDialog;
import com.example.dialoglibrary.util.Config;
import com.example.dialoglibrary.util.DialogUtils;
import com.github.chrisbanes.photoview.OnPhotoTapListener;
import com.github.chrisbanes.photoview.OnViewTapListener;
import com.github.chrisbanes.photoview.PhotoView;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class DialogTestActivity extends AppCompatActivity implements View.OnClickListener {

    private Button btnDialog0;
    private Button btnDialog00;
    private Button btnDialog000;
    private Button btnDialog1;
    private Button btnDialog2;
    private Button btnDialog3;
    private Button btnDialog4;
    private Button btnDialog5;
    private Button btnDialog6;
    private Button btnDialog7;
    private Button btnDialog8;
    private Button btnDialog9;
    private Button btnDialog10;
    private Button btnDialog11;
    private Button btnDialog12;
    private CustomDialog mDialog0;
    private CustomDialog mDialog00;
    private CustomDialog mDialog000;
    private String url = "http://b.hiphotos.baidu.com/image/pic/item/d1160924ab18972bf5f68cc8e0cd7b899f510ae7.jpg";
    private String url1 = "https://wx4.sinaimg.cn/mw690/6e464f7bgy1gcfjknuibgj20u01hctk0.jpg";
    private String url2 = "https://wx3.sinaimg.cn/thumb180/0060Ga9Zly1gcfjm66l2oj30q80k0137.jpg";
    private String url3 = "https://wx2.sinaimg.cn/thumb180/007ZkA6Yly1gcfjmhx9inj30d20d2my5.jpg";
    private ImageView iv;
    private ArrayList<String> urls = new ArrayList<>();

    /**
     * 获取当前设备的屏幕密度等基本参数
     */
    protected void getDeviceDensity() {
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        Config.EXACT_SCREEN_HEIGHT = metrics.heightPixels;
        Config.EXACT_SCREEN_WIDTH = metrics.widthPixels;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_dialog);

        iv = (ImageView) findViewById(R.id.iv);
        Glide.with(this)
                .load(url)
                .placeholder(R.drawable.ic_launcher)
                .error(R.drawable.ic_launcher)
                .into(iv);
        btnDialog0 = (Button) findViewById(R.id.btn_dialog_0);
        btnDialog00 = (Button) findViewById(R.id.btn_dialog_00);
        btnDialog000 = (Button) findViewById(R.id.btn_dialog_000);
        btnDialog1 = (Button) findViewById(R.id.btn_dialog_1);
        btnDialog2 = (Button) findViewById(R.id.btn_dialog_2);
        btnDialog3 = (Button) findViewById(R.id.btn_dialog_3);
        btnDialog4 = (Button) findViewById(R.id.btn_dialog_4);
        btnDialog5 = (Button) findViewById(R.id.btn_dialog_5);
        btnDialog6 = (Button) findViewById(R.id.btn_dialog_6);
        btnDialog7 = (Button) findViewById(R.id.btn_dialog_7);
        btnDialog8 = (Button) findViewById(R.id.btn_dialog_8);
        btnDialog9 = (Button) findViewById(R.id.btn_dialog_9);
        btnDialog10 = (Button) findViewById(R.id.btn_dialog_10);
        btnDialog11 = (Button) findViewById(R.id.btn_dialog_11);
        btnDialog12 = (Button) findViewById(R.id.btn_dialog_12);
        btnDialog0.setOnClickListener(this);
        btnDialog00.setOnClickListener(this);
        btnDialog000.setOnClickListener(this);
        btnDialog1.setOnClickListener(this);
        btnDialog2.setOnClickListener(this);
        btnDialog3.setOnClickListener(this);
        btnDialog4.setOnClickListener(this);
        btnDialog5.setOnClickListener(this);
        btnDialog6.setOnClickListener(this);
        btnDialog7.setOnClickListener(this);
        btnDialog8.setOnClickListener(this);
        btnDialog9.setOnClickListener(this);
        btnDialog10.setOnClickListener(this);
        btnDialog11.setOnClickListener(this);
        btnDialog12.setOnClickListener(this);

        getDeviceDensity();
        urls = new ArrayList<>();
        urls.add(url);
        urls.add(url1);
        urls.add(url2);
        urls.add(url3);
//        urls.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-05-05-18251898_1013302395468665_8734429858911748096_n.jpg");
//        urls.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-05-04-18299181_1306649979420798_1108869403736276992_n.jpg");
//        urls.add("http://ww1.sinaimg.cn/large/61e74233ly1feuogwvg27j20p00zkqe7.jpg");
//        urls.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-05-02-926821_1453024764952889_775781470_n.jpg");
//        urls.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-04-28-18094719_120129648541065_8356500748640452608_n.jpg");
//        urls.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-04-27-17934080_117414798808566_8957027985114791936_n.jpg?imageslim");
//        urls.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-04-25-13651793_897557617014845_571817176_n.jpg");
//        urls.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-04-24-18013547_1532023163498554_215541963087151104_n.jpg");
//        urls.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-04-24-18094714_158946097967074_5909424912493182976_n.jpg");
    }

    static class SamplePagerAdapter extends PagerAdapter {

        private static final int[] sDrawables = {R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher,
                R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher};

        @Override
        public int getCount() {
            return sDrawables.length;
        }

        @Override
        public View instantiateItem(ViewGroup container, int position) {
            PhotoView photoView = new PhotoView(container.getContext());
            photoView.setImageResource(sDrawables[position]);
            // Now just add PhotoView to ViewPager and return it
            container.addView(photoView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            return photoView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

    }


    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.btn_dialog_0) {
            showDialog0();
        } else if (id == R.id.btn_dialog_00) {
            showDialog00();
        } else if (id == R.id.btn_dialog_000) {
            showDialog000();
        } else if (id == R.id.btn_dialog_1) {
            showDialog1();
        } else if (id == R.id.btn_dialog_2) {
            showDialog2();
        } else if (id == R.id.btn_dialog_3) {
            showDialog3();
        } else if (id == R.id.btn_dialog_4) {
            showDialog4();
        } else if (id == R.id.btn_dialog_5) {
            showDialog5();
        } else if (id == R.id.btn_dialog_6) {
            showDialog6();
        } else if (id == R.id.btn_dialog_7) {
            showDialog7();
        } else if (id == R.id.btn_dialog_8) {
            showDialog8();
        } else if (id == R.id.btn_dialog_9) {
            showDialog9();
        } else if (id == R.id.btn_dialog_10) {
            showDialog10();
        } else if (id == R.id.btn_dialog_11) {
            showDialog11();
        } else if (id == R.id.btn_dialog_12) {
            showDialog12();
        }
    }

    private void showDialog000() {
        new ShowImagesDialog(this, urls).show();
    }

    private class MyAdapter extends FragmentPagerAdapter {

        public MyAdapter(@NonNull FragmentManager fm) {
            super(fm);
        }

        public MyAdapter(@NonNull FragmentManager fm, int behavior) {
            super(fm, behavior);
        }

        @NonNull
        @Override
        public Fragment getItem(int position) {
            return null;
        }

        @Override
        public int getCount() {
            return 0;
        }
    }

    private void showDialog00() {
        mDialog00 = new CustomDialog.Builder(this)
                .style(R.style.transparentBgDialog)
                .setContentView(R.layout.dialog_photo_multi)
                .width(getActivityWidthPixels(this))
                .height(getActivityHeightPixels(this))
                .build();
        ViewPager viewPager = mDialog00.getView(R.id.view_pager, ViewPager.class);
        viewPager.setAdapter(new SamplePagerAdapter());
        mDialog00.show();
    }

    private void showDialog0() {
        mDialog0 = new CustomDialog.Builder(this)
                .style(R.style.transparentBgDialog)
                .setContentView(R.layout.dialog_photo_single)
                .width(getActivityWidthPixels(this))
                .height(getActivityHeightPixels(this))
                .build();
        PhotoView photoView = mDialog0.getView(R.id.pv_images, PhotoView.class);
        photoView.setOnPhotoTapListener(new OnPhotoTapListener() {
            @Override
            public void onPhotoTap(ImageView view, float x, float y) {
                mDialog0.dismiss();
            }
        });
        //点击图片外围（无图片处）监听
        photoView.setOnViewTapListener(new OnViewTapListener() {
            @Override
            public void onViewTap(View view, float x, float y) {
                mDialog0.dismiss();
            }
        });
        Glide.with(this)
                .load(url)
                .placeholder(R.drawable.ic_launcher)
                .error(R.drawable.ic_launcher)
                .into(photoView);
        mDialog0.show();
    }


    public static int getActivityWidthPixels(Activity activity) {
        DisplayMetrics metrics = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
        return metrics.widthPixels;
    }

    public int getActivityHeightPixels(Activity activity) {
        DisplayMetrics metrics = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
        return metrics.heightPixels;
    }

    //自定义适配器对话框
    private void showDialog12() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("设置");
        builder.setIcon(R.drawable.ic_launcher);

        String[] arrStrings = {"系统设置", "WIFI设置", "网络设置", "声音设置", "日期设置"};
        int[] imgids = {R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher};

        List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
        for (int i = 0; i < imgids.length; i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("img", imgids[i]);
            map.put("settings", arrStrings[i]);    //img和settings为自定义名字

            data.add(map);
        }

        SimpleAdapter adapter = new SimpleAdapter(this,     //上下文
                data,       //list<map<.>数据源
                R.layout.dialog_item,     //子布局文件
                new String[]{"img", "settings"},    //from从哪里拿数据
                new int[]{R.id.imageView_item_dialog_icon, R.id.text_item_dialog_setting});       //to把数据放哪里

        builder.setAdapter(adapter, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent();
                switch (which) {
                    case 0:
                        intent.setAction(Settings.ACTION_SETTINGS);
                        break;
                    case 1:
                        intent.setAction(Settings.ACTION_WIFI_SETTINGS);
                        break;
                    case 2:
                        intent.setAction(Settings.ACTION_NETWORK_OPERATOR_SETTINGS);
                        break;
                    case 3:
                        intent.setAction(Settings.ACTION_SOUND_SETTINGS);
                        break;
                    case 4:
                        intent.setAction(Settings.ACTION_DATE_SETTINGS);
                        break;
                }
                startActivity(intent);
            }
        });

        builder.show();
    }

    //多选
    private void showDialog11() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);  //先得到构造器
        builder.setTitle("提示"); //设置标题
        builder.setIcon(R.drawable.ic_launcher);//设置图标，图片id即可

        final String items[] = {"篮球", "足球", "排球"};
        final boolean selected[] = {true, false, true};
        builder.setMultiChoiceItems(items, selected, new DialogInterface.OnMultiChoiceClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                // dialog.dismiss();
                Toast.makeText(DialogTestActivity.this, items[which] + isChecked, Toast.LENGTH_SHORT).show();
            }
        });
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                Toast.makeText(DialogTestActivity.this, "确定", Toast.LENGTH_SHORT).show();
                //android会自动根据你选择的改变selected数组的值。
                for (int i = 0; i < selected.length; i++) {
                    Log.e("hongliang", "" + selected[i]);
                }
            }
        });
        builder.create().show();
    }

    //单选
    private void showDialog10() {
        final String items[] = {"男", "女"};
        AlertDialog.Builder builder = new AlertDialog.Builder(this);  //先得到构造器
        builder.setTitle("提示"); //设置标题
        builder.setIcon(R.drawable.ic_launcher);//设置图标，图片id即可

        builder.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //dialog.dismiss();
                Toast.makeText(DialogTestActivity.this, items[which], Toast.LENGTH_SHORT).show();
            }
        });
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                Toast.makeText(DialogTestActivity.this, "确定", Toast.LENGTH_SHORT).show();
            }
        });
        builder.create().show();
    }

    //普通列表
    private void showDialog9() {
        //dialog参数设置
        AlertDialog.Builder builder = new AlertDialog.Builder(this);  //先得到构造器
        builder.setTitle("提示"); //设置标题
        //builder.setMessage("是否确认退出?"); //设置内容
        builder.setIcon(R.drawable.ic_launcher);//设置图标，图片id即可
        //设置列表显示，注意设置了列表显示就不要设置builder.setMessage()了，否则列表不起作用。

        final String items[] = {"张三", "李四", "王五"};
        builder.setItems(items, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                    case 0:
                        break;
                    case 1:
                        break;
                    case 2:
                        break;
                    default:
                        break;
                }
                dialog.dismiss();
                Toast.makeText(DialogTestActivity.this, items[which], Toast.LENGTH_SHORT).show();

            }
        });
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                Toast.makeText(DialogTestActivity.this, "确定", Toast.LENGTH_SHORT).show();
            }
        });
        builder.create().show();
    }

    //时间选择器
    private void showDialog8() {
        Calendar calendar = Calendar.getInstance();
        TimePickerDialog timePickerDialog = new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker arg0, int hour, int minute) {
                Toast.makeText(DialogTestActivity.this, "您选择了：" + hour + ":" + minute, Toast.LENGTH_SHORT).show();
            }
        }, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true);
        timePickerDialog.setCancelable(true);
        timePickerDialog.show();
    }

    //日期选择器
    private void showDialog7() {
        Calendar calendar = Calendar.getInstance();
        DatePickerDialog datePickerDialog = new DatePickerDialog(DialogTestActivity.this, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                Toast.makeText(DialogTestActivity.this, "您选择了：" + year + "-" + (monthOfYear + 1) +
                        "-" + dayOfMonth, Toast.LENGTH_SHORT).show();
            }
        }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
        datePickerDialog.setCancelable(true);
        datePickerDialog.show();
    }

    //水平进度条
    private void showDialog6() {
        // 进度条还有二级进度条的那种形式，这里就不演示了
        final ProgressDialog dialog = new ProgressDialog(this);
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);// 设置水平进度条
        dialog.setCancelable(true);// 设置是否可以通过点击Back键取消
        dialog.setCanceledOnTouchOutside(false);// 设置在点击Dialog外是否取消Dialog进度条
        dialog.setIcon(R.drawable.ic_launcher);// 设置提示的title的图标，默认是没有的
        dialog.setTitle("提示");
        dialog.setMax(100);
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定",
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "取消",
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
        dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "中立",
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
        dialog.setMessage("这是一个水平进度条");
        dialog.show();
        new Thread(new Runnable() {

            @Override
            public void run() {
                int i = 0;
                while (i < 100) {
                    try {
                        Thread.sleep(200);
                        //progressDialog.setProgress(i);
                        // 更新进度条的进度,可以在子线程中更新进度条进度
                        dialog.incrementProgressBy(1);
                        // dialog.incrementSecondaryProgressBy(10)//二级进度条更新方式
                        i++;

                    } catch (Exception e) {
                    }
                }
                // 在进度条走完时删除Dialog
                dialog.dismiss();
                // // 调用cancel方法会回调DialogInterface.OnCancelListener，dismiss不会回调
            }
        }).start();
    }

    //圆型进度条
    private void showDialog5() {
        final ProgressDialog dialog = new ProgressDialog(this);
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);// 设置进度条的形式为圆形转动的进度条
        dialog.setCancelable(true);// 设置是否可以通过点击Back键取消
        dialog.setCanceledOnTouchOutside(false);// 设置在点击Dialog外是否取消Dialog进度条
        dialog.setIcon(R.drawable.ic_launcher);//
        // 设置提示的title的图标，默认是没有的，如果没有设置title的话只设置Icon是不会显示图标的
        dialog.setTitle("提示");
        // dismiss监听
        dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialog) {

            }
        });
        // 监听Key事件被传递给dialog
        dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {

            @Override
            public boolean onKey(DialogInterface dialog, int keyCode,
                                 KeyEvent event) {
                return false;
            }
        });
        // 监听cancel事件
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {

            }
        });
        //设置可点击的按钮，最多有三个(默认情况下)
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定",
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "取消",
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
        dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "中立",
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
        dialog.setMessage("这是一个圆形进度条");
        dialog.show();
        new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    Thread.sleep(5000);
                    // cancel和dismiss方法本质都是一样的，都是从屏幕中删除Dialog,唯一的区别是
                    // 调用cancel方法会回调DialogInterface.OnCancelListener如果注册的话,dismiss方法不会回掉
                    dialog.cancel();
                    // dialog.dismiss();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    private CustomDialog dialog1;
    private CustomDialog dialog2;
    private CustomDialog dialog3;
    private CustomDialog dialog4;


    private void showDialog1() {
        dialog1 = new CustomDialog.Builder(this)
                .setContentView(R.layout.dialog_single_choice)
                .dimAmount(0.2f)
                .addViewOnclick(R.id.tv_single_choice_confirm, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog1.dismiss();
                        toast("一个选择：知道了");
                    }
                })
                .setText(R.id.tv_single_choice_confirm, "我同意")
                .setText(R.id.tv_single_choice_content, "这次的数字是 ： " + new Random().nextInt())
                .build();
        dialog1.show();
    }

    private void showDialog2() {
        dialog2 = new CustomDialog.Builder(this)
                .setContentView(R.layout.dialog_double_choice)
                .cancelable(true)
                .dimAmount(0.8f)
                .canceledOnTouchOutside(true)
                .animation(R.style.dialogWindowAnim)
                .gravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL)
                .addViewOnclick(R.id.tv_double_choice_negative, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog2.dismiss();
                        toast("两个选择：选择了放弃");
                    }
                })
                .addViewOnclick(R.id.tv_double_choice_positive, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog2.dismiss();
                        toast("两个选择：选择了下一步");
                    }
                })
                .setText(R.id.tv_double_choice_negative, "放弃吧")
                .setText(R.id.tv_double_choice_positive, "继续战斗")
                .setText(R.id.tv_double_choice_content, "这次的数字是 ： " + new Random().nextInt())
                .build();
        dialog2.show();
    }

    private void showDialog3() {
        dialog3 = new CustomDialog.Builder(this)
                .setContentView(R.layout.custom_dialog_layout)
                .width((int) (DialogUtils.getDeviceWidth(this) * 0.85f))
                .height(ViewGroup.LayoutParams.WRAP_CONTENT)
                .addViewOnclick(R.id.tv_no, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog3.dismiss();
                        toast("两个选择：no no no ");
                    }
                })
                .addViewOnclick(R.id.tv_yes, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog3.dismiss();
                        toast("两个选择：yes yes yes");
                    }
                })
                .setText(R.id.tv_yes, "yes")
                .setText(R.id.tv_no, "no")
                .setText(R.id.tv_title, "title")
                .setText(R.id.tv_message, "message")
                .build();
        dialog3.show();
    }

    private void showDialog4() {
        String[] strings = getResources().getStringArray(R.array.strings);
        DialogAdapter adapter = new DialogAdapter(this, strings);
        dialog4 = new CustomDialog.Builder(this)
                .setContentView(R.layout.layout_common_dialog)
                .height(ViewGroup.LayoutParams.WRAP_CONTENT)
                .gravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL)
                .cancelable(true)
                .canceledOnTouchOutside(true)
                .animation(R.style.dialogWindowAnim)
                .width(DialogUtils.getDeviceWidth(this) - DialogUtils.dp2px(this, 20f))
                .addViewOnclick(R.id.btn_dialog_cancel, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog4.dismiss();
                        toast("我不选择。。。");
                    }
                })
                .setText(R.id.tv_dialog_title, "选一个吧")
                .setText(R.id.btn_dialog_cancel, "下次再选")
                .setAdapter(R.id.rv_dialog, adapter)
                .build();
        adapter.setClickItemListener(new DialogAdapter.OnClickItemListener() {
            @Override
            public void onClickItem(int position, String message) {
                toast("您点击了：" + message);
                dialog4.dismiss();
            }
        });
        dialog4.show();
    }

    private void toast(String message) {
        Toast.makeText(DialogTestActivity.this, message, Toast.LENGTH_SHORT).show();
    }
}
